package com.factory.mapper;

import com.factory.dao.SaleRecord;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SaleRecordMapper {
    @Select("select \n" +
            "c.name as customerName,\n" +
            "\t(\n" +
            "\tSELECT SUM\n" +
            "\t\t( sd.selling_number* sd.selling_price ) \n" +
            "\tFROM\n" +
            "\t\tsale_detail sd \n" +
            "\tWHERE\n" +
            "\t\tsd.saleid= s.id \n" +
            "\t\tAND sd.isdelete= 0 \n" +
            "\tGROUP BY\n" +
            "\t\tsd.saleid \n" +
            "\t) AS sumMoney,s.time,\n" +
            "s.remarks,\n" +
            "u.name as username,\n" +
            "s.id\n" +
            "from sale s\n" +
            "left join [user] u on u.id=s.userid\n" +
            "left join customer c on c.id=s.customerid\n" +
            "where isdelete=0")
    List<SaleRecord> queryAll();

}
